#ifndef CMDLTREEVIEW_H
#define CMDLTREEVIEW_H

#include <QTreeWidget>
#include "CEntity.h"
#include "CMdlTreeNode.h"

using namespace csmodel;

class CMdlTreeView : public QTreeWidget
{
    CEntity * root;
    std::set< CEntity* > expanded;
    std::vector< CEntity* > selection;
    int focus;
    CEntity * deferredFocusEntity;
    std::vector< CMdlTreeNode* > map;
    CMdlTreeTraits treeTraits;
    CMdlTreeNode * treeRoot;
    bool updateInProgress;

public:
    explicit CMdlTreeView(QWidget *parent = 0);
    QString GetEntityText( CEntity * e );
    QRect GetNodeRect( CMdlTreeNode * node, int x, int y );
    void ExpandEntityNode( CEntity * e );
    bool EntityNodeExpanded( CEntity * e );
    void CollapseEntityNode( CEntity * e );
    bool EntityNodeCollapsed( CEntity * e );

    void SetRoot( CEntity* r ) { root = r; }

    CEntity* GetSelected();
    void SetSelected( CEntity * e );
    void ClearSelection();


    void Update() { if( !updateInProgress ) EndUpdate(); }
    void BeginUpdate() { updateInProgress = true; }
    void EndUpdate();

protected:
    CMdlTreeNode * MapEntities( CEntity * e = 0 );

    void ResetSelected( CEntity * e );
    void AddToSelection( CEntity * e );
    void FocusEntity( CEntity * e );
    void ShowEntity( CEntity * e, bool setFocus = false );
    void FillTree();
    void selectNodes();

signals:
    
public slots:
    
};

#endif // CMDLTREEVIEW_H
